//
//  HNSH_GroupChatInfoSwitchCell.m
//  HNSH_SingleProject
//
//  Created by 李宇廷 on 2023/2/17.
//

#import "HNSH_GroupChatInfoSwitchCell.h"

@interface HNSH_GroupChatInfoSwitchCell ()
/** */
@property (nonatomic, strong)UILabel * titleLabel;
@end

@implementation HNSH_GroupChatInfoSwitchCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        [self addAllViews];
        [self addAllLayout];
    }
    return self;
}

//MARK: Myself Methods
- (void)addAllViews{
    self.backgroundColor = [UIColor appWhiteLabelColor];
    [self.contentView addSubview:self.titleLabel];
    [self.contentView addSubview:self.switchView];
    [self.contentView addSubview:self.openButton];
}

- (void)addAllLayout{
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(16);
        make.top.height.mas_equalTo(self.contentView);
    }];
    [self.switchView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.width.mas_equalTo(48);
        make.height.mas_equalTo(30);
        make.centerY.mas_equalTo(self.titleLabel);
    }];
    
    [self.openButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_equalTo(-16);
        make.width.mas_equalTo(60);
        make.height.mas_equalTo(30);
        make.centerY.mas_equalTo(self.titleLabel);
    }];
}

//MARK: Setter Methods
- (void)setDic:(NSDictionary *)dic{
    _dic = dic;
    
    self.titleLabel.text = dic[@"title"];
    self.switchView.on = [dic[@"isOn"] boolValue];
}

//MARK: Getter Methods
- (UILabel *)titleLabel{
    if (!_titleLabel) {
        _titleLabel = [UILabel new];
        _titleLabel.font = [UIFont systemFontOfSize:15];
        _titleLabel.textColor = [UIColor blackColor];
    }
    return _titleLabel;
}

- (UISwitch *)switchView{
    if (!_switchView) {
        _switchView = [UISwitch new];
        _switchView.onTintColor = [UIColor appGreenColor];
        _switchView.hidden = YES;
    }
    return _switchView;
}

- (UIButton *)openButton {
    if (!_openButton) {
        _openButton = [UIButton buttonWithType:UIButtonTypeCustom];
        [_openButton setTitle:@"开启" forState:UIControlStateNormal];
        [_openButton setTitle:@"已开启" forState:UIControlStateSelected];
        [_openButton setTitleColor:[UIColor colorWithHexString:@"#FFFFFF"] forState:UIControlStateNormal];
        [_openButton setTitleColor:[UIColor colorWithHexString:@"#999999"] forState:UIControlStateSelected];
        _openButton.titleLabel.font = [UIFont systemFontOfSize:14];
        _openButton.backgroundColor = [UIColor appBlackLabelColor];
        _openButton.hidden = YES;
        _openButton.layer.cornerRadius = 6;
        _openButton.layer.masksToBounds = YES;
    }
    return _openButton;
}
@end
